package cn.guo.action;



import cn.guo.entity.User;
import cn.guo.service.IUserService;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

/**
 * 用户登陆注册模块
 * 1. 登陆
 *
 */
public class UserAction extends ActionSupport implements ModelDriven<User> {

	// 封装请求数据
	private User user = new User();
	public void setUser(User user) {
		this.user = user;
	}
	public User getUser() {
		return user;
	}
	
	public User getModel() {
		return user;
	}
	
	// 调用Service
	private IUserService userService;
	public void setUserService(IUserService userService) {
		this.userService = userService;
	}
	
	/**
	 * 登陆
	 */
	public String login(){
		// 登陆验证
		User userInfo = userService.login(user);
		// 验证
		if (userInfo == null){
			// 登陆失败
			return "loginFaild";
		} else {
			// 登陆成功, 保存数据到session
			ActionContext.getContext().getSession().put("userInfo", userInfo);
			return "index";
		}
	}

}
